<?php
$isReloadable = true;
require_once("../../../pers/inc.config.php");
require_once(OVF_FS_WEB_ROOT.'/app/_inc/inc.session.php');
require_once(OVF_FS_WEB_ROOT.'/app/_inc/funct.html.php');
require_once OVF_FS_WEB_ROOT.'/app/_inc/class.ovfForm.php';

$sSql = "SELECT a.*, au.id_utente, u.nome, u.cognome "
	.", tc.descr AS TC_des, tc.pallino AS TC_pallino "
	.", an.intestaz1 "
	." FROM ovf_agenda a "
	." LEFT JOIN ovf_agenda_utenti au ON au.id_agenda = a.id_agenda "
	." LEFT JOIN ovf_utenti u ON u.id_utente = au.id_utente "
	." LEFT JOIN ovf_agenda_tipi_cont tc ON tc.id_tipo_cont = a.id_tipo_cont \n"
	." LEFT JOIN ovf_anagrafiche an ON an.id_anag = a.id_anag \n"
	." WHERE a.id_agenda = ".reqVarInt('id');
$objDB->query($sSql,'selAge');	
if (!$acAge = $objDB->fetch('selAge')) {
	backOnErr("id '".reqVar('id')."' errato");
}
$acX = $acAge;
dbg_($acAge);
$aAgende = array();
while($acX) {
	$aAgende[$acX['id_utente']] = $acX['nome']." ".$acX['cognome'];
	$acX = $objDB->fetch('selAge');
}
$agendeTxt = implode(", ",$aAgende);

if (reqVar('azione') == 'elimina') {
	$msgPag = confEli();
} 

// testata sezione anagrafica
$oFormTestaSez = new ovfForm('testasez');
//dbg_($oForm);
$sSql = "SELECT ".$oFormTestaSez->getCampiSelect()
   ." FROM ovf_anagrafiche A WHERE A.id_anag = ".$acAge['id_anag'];
$objDB->query($sSql);
if (!$oFormTestaSez->aCampiDB = $objDB->fetch()) {
   backOnErr("id. errato '".$idAnag."'");
}
$oFormTestaSez->db2form();

$sHtmlAnag = "<table class=\"tab1\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"100%\" align='center'>";
$sHtmlAnag .= getHtmlRigaRif();
$sHtmlAnag .= $oFormTestaSez->getHtmlCampiView();
$sHtmlAnag .= "</table>";


$sCmdR = '';
$sCmdR .= "&nbsp;&nbsp;&nbsp;";
$sCmdR .= "<a class=\"cmd1\" href=\"javascript:confEli();\" >elimina</a>\n";
$sCmdR .= "&nbsp;&nbsp;&nbsp;";
$sCmdR .= "<a class=\"cmd1\" href=\"javascript:goModif();\" >modifica</a>\n";
$sCmdR .= cmdTorna('torna'); 

$aOpz['sottotit'] = $sHtmlAnag;
testaHtml('Anagrafe','Scheda contatto',$msgPag,'rcom',$aOpz);
?>
<script type="text/javascript">
<!--
function goModif() {
	document.frm1.action = 'contMod.php';
	document.frm1.submit();	
}
function confEli() {
	if (confirm("confermi l'eliminazione ?")) {
		document.frm1.azione.value = 'elimina';
		document.frm1.submit();
	}
}
//-->
</script>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="right"><?php echo $sCmdR;?></td>
   </tr>
</table>
<?=getHtmlForm('frm1','',array('enctype'=>true));?>
<?=getHtmlHidden('azione','');?>
<?=getHtmlHidden('id');?>
<?=getHtmlHidden('xsn',XSN);?>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
	<?=getHtmlRigaRif(20);?>
   <tr>
      <td class="tit1" colspan='20' align='center'>Contatto</td>
   </tr>
   <tr>
      <td class="lab1" colspan='3' align='left'>Agenti</td>
      <td class="txt1" colspan='17' align='left'>
      <?php echo $agendeTxt;?>
		</td>
   </tr>
   <tr>
      <td class="lab1" colspan='3' align='left'>Oggetto</td>
      <td class="txt1" colspan='17' align='left'>
      	<?php echo $acAge['oggetto']?>
		</td>
   </tr>
   <tr>
      <td class="lab1" colspan='3' align='left'>Data</td>
      <td class="txt1" colspan='3' align='left'>
      	<?php echo YMD2DMY($acAge['data_agenda'])?>
		</td>
    <td class="lab1" colspan='1' align='left'>Dove</td>
      <td class="txt1" colspan='13' align='left'>
      	<?php echo $acAge['dove']?>
		</td>
	</tr>
   <tr>
      <td class="lab1" colspan='3' align='left'>Tipo</td>
      <td class="txt1" colspan='17' align='left'>
         <?php 
            if ($acAge['TC_pallino']=='') {
               $pallinoImg = "vuoto.png";
               $des = $acAge['TC_des'];
            } else {
               $pallinoImg = $acAge['TC_pallino'].".gif" ;
               $des = $acAge['TC_des'];
            }
            echo "<img src=\"".OVF_URL_ROOT."/app/_img/pallino_ti_$pallinoImg\" border='0'/>&nbsp;&nbsp;";
            echo $des;
         ?>
      </td>
   </tr>
   <tr>
      <td class="lab1" colspan='3' align='left'>Nota</td>
      <td class="txt1" colspan='17' align='left'>
         <?php echo getHtmlViewText($acAge['nota']);?>
      </td>
   </tr>
</table>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="right"><?php echo $sCmdR;?></td>
   </tr>
</table>
<?
echo "</form>\n";
codaHtml();
exit();

function confEli() {
	return "todo";
}
